<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="author" content="Yukai Yang" />

<meta name="date" content="2019-06-03" />

<title>Panel Smooth Transition Regression</title>



<style type="text/css">code{white-space: pre;}</style>
<style type="text/css" data-origin="pandoc">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
  { position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
  { content: attr(title);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; pointer-events: all; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {  }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */

</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
  var sheets = document.styleSheets;
  for (var i = 0; i < sheets.length; i++) {
    if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
    try { var rules = sheets[i].cssRules; } catch (e) { continue; }
    for (var j = 0; j < rules.length; j++) {
      var rule = rules[j];
      // check if there is a div.sourceCode rule
      if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
      var style = rule.style.cssText;
      // check if color or background-color is set
      if (rule.style.color === '' || rule.style.backgroundColor === '') continue;
      // replace div.sourceCode by a pre.sourceCode rule
      sheets[i].deleteRule(j);
      sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
    }
  }
})();
</script>



<style type="text/css">body {
background-color: #fff;
margin: 1em auto;
max-width: 700px;
overflow: visible;
padding-left: 2em;
padding-right: 2em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.35;
}
#header {
text-align: center;
}
#TOC {
clear: both;
margin: 0 0 10px 10px;
padding: 4px;
width: 400px;
border: 1px solid #CCCCCC;
border-radius: 5px;
background-color: #f6f6f6;
font-size: 13px;
line-height: 1.3;
}
#TOC .toctitle {
font-weight: bold;
font-size: 15px;
margin-left: 5px;
}
#TOC ul {
padding-left: 40px;
margin-left: -1.5em;
margin-top: 5px;
margin-bottom: 5px;
}
#TOC ul ul {
margin-left: -2em;
}
#TOC li {
line-height: 16px;
}
table {
margin: 1em auto;
border-width: 1px;
border-color: #DDDDDD;
border-style: outset;
border-collapse: collapse;
}
table th {
border-width: 2px;
padding: 5px;
border-style: inset;
}
table td {
border-width: 1px;
border-style: inset;
line-height: 18px;
padding: 5px 5px;
}
table, table th, table td {
border-left-style: none;
border-right-style: none;
}
table thead, table tr.even {
background-color: #f7f7f7;
}
p {
margin: 0.5em 0;
}
blockquote {
background-color: #f6f6f6;
padding: 0.25em 0.75em;
}
hr {
border-style: solid;
border: none;
border-top: 1px solid #777;
margin: 28px 0;
}
dl {
margin-left: 0;
}
dl dd {
margin-bottom: 13px;
margin-left: 13px;
}
dl dt {
font-weight: bold;
}
ul {
margin-top: 0;
}
ul li {
list-style: circle outside;
}
ul ul {
margin-bottom: 0;
}
pre, code {
background-color: #f7f7f7;
border-radius: 3px;
color: #333;
white-space: pre-wrap; 
}
pre {
border-radius: 3px;
margin: 5px 0px 10px 0px;
padding: 10px;
}
pre:not([class]) {
background-color: #f7f7f7;
}
code {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-size: 85%;
}
p > code, li > code {
padding: 2px 0px;
}
div.figure {
text-align: center;
}
img {
background-color: #FFFFFF;
padding: 2px;
border: 1px solid #DDDDDD;
border-radius: 3px;
border: 1px solid #CCCCCC;
margin: 0 5px;
}
h1 {
margin-top: 0;
font-size: 35px;
line-height: 40px;
}
h2 {
border-bottom: 4px solid #f7f7f7;
padding-top: 10px;
padding-bottom: 2px;
font-size: 145%;
}
h3 {
border-bottom: 2px solid #f7f7f7;
padding-top: 10px;
font-size: 120%;
}
h4 {
border-bottom: 1px solid #f7f7f7;
margin-left: 8px;
font-size: 105%;
}
h5, h6 {
border-bottom: 1px solid #ccc;
font-size: 105%;
}
a {
color: #0033dd;
text-decoration: none;
}
a:hover {
color: #6666ff; }
a:visited {
color: #800080; }
a:visited:hover {
color: #BB00BB; }
a[href^="http:"] {
text-decoration: underline; }
a[href^="https:"] {
text-decoration: underline; }

code > span.kw { color: #555; font-weight: bold; } 
code > span.dt { color: #902000; } 
code > span.dv { color: #40a070; } 
code > span.bn { color: #d14; } 
code > span.fl { color: #d14; } 
code > span.ch { color: #d14; } 
code > span.st { color: #d14; } 
code > span.co { color: #888888; font-style: italic; } 
code > span.ot { color: #007020; } 
code > span.al { color: #ff0000; font-weight: bold; } 
code > span.fu { color: #900; font-weight: bold; }  code > span.er { color: #a61717; background-color: #e3d2d2; } 
</style>




</head>

<body>




<h1 class="title toc-ignore">Panel Smooth Transition Regression</h1>
<h4 class="author">Yukai Yang</h4>
<h4 class="date">2019-06-03</h4>



<div id="pstr-version-1.2.5-orange-panel" class="section level1">
<h1>PSTR version 1.2.5 (Orange Panel)</h1>
<p>The PSTR package implements the Panel Smooth Transition Regression (PSTR) modelling. You can find the package on CRAN, see</p>
<p><a href="https://CRAN.R-project.org/package=PSTR">PSTR@CRAN</a></p>
<p>The modelling procedure consists of three stages: Specification, Estimation and Evaluation. The package offers tools helping the users to conduct model specification tests, to do PSTR model estimation, and to do model evaluation.</p>
<p>The cluster-dependency and heteroskedasticity-consistent tests are implemented in the package.</p>
<p>The wild bootstrap and cluster wild bootstrap tests are also implemented.</p>
<p>Parallel computation (as an option) is implemented in some functions, especially the bootstrap tests. Therefore, the package suits tasks running many cores on super-computation servers.</p>
<div id="how-to-install" class="section level2">
<h2>How to install</h2>
<p>You can either install the stable version from CRAN</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">install.packages</span>(<span class="st">&quot;PSTR&quot;</span>)</a></code></pre></div>
<p>or install the development version from GitHub</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">devtools<span class="op">::</span><span class="kw">install_github</span>(<span class="st">&quot;yukai-yang/PSTR&quot;</span>)</a></code></pre></div>
<p>provided that the package “devtools” has been installed beforehand.</p>
</div>
<div id="example" class="section level2">
<h2>Example</h2>
<p>After installing the package, you need to load (attach better say) it by running the code</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1"><span class="kw">library</span>(PSTR)</a>
<a class="sourceLine" id="cb3-2" title="2"><span class="co">#&gt; Registered S3 methods overwritten by &#39;ggplot2&#39;:</span></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="co">#&gt;   method         from </span></a>
<a class="sourceLine" id="cb3-4" title="4"><span class="co">#&gt;   [.quosures     rlang</span></a>
<a class="sourceLine" id="cb3-5" title="5"><span class="co">#&gt;   c.quosures     rlang</span></a>
<a class="sourceLine" id="cb3-6" title="6"><span class="co">#&gt;   print.quosures rlang</span></a></code></pre></div>
<p>You can first check the information and the current version number by running</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="kw">version</span>()</a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co">#&gt; PSTR version 1.2.4 (Orange Panel)</span></a></code></pre></div>
<p>Then you can take a look at all the available functions and data in the package</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1"><span class="kw">ls</span>( <span class="kw">grep</span>(<span class="st">&quot;PSTR&quot;</span>, <span class="kw">search</span>()) ) </a>
<a class="sourceLine" id="cb5-2" title="2"><span class="co">#&gt;  [1] &quot;EstPSTR&quot;           &quot;EvalTest&quot;          &quot;Hansen99&quot;         </span></a>
<a class="sourceLine" id="cb5-3" title="3"><span class="co">#&gt;  [4] &quot;LinTest&quot;           &quot;NewPSTR&quot;           &quot;WCB_HETest&quot;       </span></a>
<a class="sourceLine" id="cb5-4" title="4"><span class="co">#&gt;  [7] &quot;WCB_LinTest&quot;       &quot;WCB_TVTest&quot;        &quot;plot_coefficients&quot;</span></a>
<a class="sourceLine" id="cb5-5" title="5"><span class="co">#&gt; [10] &quot;plot_response&quot;     &quot;plot_target&quot;       &quot;plot_transition&quot;  </span></a>
<a class="sourceLine" id="cb5-6" title="6"><span class="co">#&gt; [13] &quot;sunspot&quot;           &quot;version&quot;</span></a></code></pre></div>
<div id="the-data" class="section level3">
<h3>The data</h3>
<p>In the package, a data set called “Hansen99” is offered to give prompt example. For details of the data set, you can run</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1">?Hansen99 </a></code></pre></div>
</div>
<div id="initialization" class="section level3">
<h3>Initialization</h3>
<p>You can create a new object of the class PSTR by doing</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1">pstr =<span class="st"> </span><span class="kw">NewPSTR</span>(Hansen99, <span class="dt">dep=</span><span class="st">&#39;inva&#39;</span>, <span class="dt">indep=</span><span class="dv">4</span><span class="op">:</span><span class="dv">20</span>, <span class="dt">indep_k=</span><span class="kw">c</span>(<span class="st">&#39;vala&#39;</span>,<span class="st">&#39;debta&#39;</span>,<span class="st">&#39;cfa&#39;</span>,<span class="st">&#39;sales&#39;</span>),</a>
<a class="sourceLine" id="cb7-2" title="2">               <span class="dt">tvars=</span><span class="kw">c</span>(<span class="st">&#39;vala&#39;</span>), <span class="dt">im=</span><span class="dv">1</span>, <span class="dt">iT=</span><span class="dv">14</span>)</a>
<a class="sourceLine" id="cb7-3" title="3"><span class="kw">print</span>(pstr)</a>
<a class="sourceLine" id="cb7-4" title="4"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb7-5" title="5"><span class="co">#&gt; ## PSTR 1.2.4 (Orange Panel)</span></a>
<a class="sourceLine" id="cb7-6" title="6"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb7-7" title="7"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb7-8" title="8"><span class="co">#&gt; Summary of the model:</span></a>
<a class="sourceLine" id="cb7-9" title="9"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb7-10" title="10"><span class="co">#&gt;   time horizon sample size = 14,  number of individuals = 560</span></a>
<a class="sourceLine" id="cb7-11" title="11"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb7-12" title="12"><span class="co">#&gt; Dependent variable:  inva</span></a>
<a class="sourceLine" id="cb7-13" title="13"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb7-14" title="14"><span class="co">#&gt; Explanatory variables in the linear part:</span></a>
<a class="sourceLine" id="cb7-15" title="15"><span class="co">#&gt;   dt_75 dt_76 dt_77 dt_78 dt_79 dt_80 dt_81 dt_82 dt_83 dt_84 dt_85 dt_86 dt_87 vala debta cfa sales</span></a>
<a class="sourceLine" id="cb7-16" title="16"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb7-17" title="17"><span class="co">#&gt; Explanatory variables in the non-linear part:</span></a>
<a class="sourceLine" id="cb7-18" title="18"><span class="co">#&gt;   vala debta cfa sales</span></a>
<a class="sourceLine" id="cb7-19" title="19"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb7-20" title="20"><span class="co">#&gt; Potential transition variable(s) to be tested:</span></a>
<a class="sourceLine" id="cb7-21" title="21"><span class="co">#&gt;   vala</span></a>
<a class="sourceLine" id="cb7-22" title="22"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb7-23" title="23"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb7-24" title="24"><span class="co">#&gt; Results of the linearity (homogeneity) tests:</span></a>
<a class="sourceLine" id="cb7-25" title="25"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb7-26" title="26"><span class="co">#&gt; Sequence of homogeneity tests for selecting number of switches &#39;m&#39;:</span></a>
<a class="sourceLine" id="cb7-27" title="27"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb7-28" title="28"><span class="co">#&gt; ###########################################################################</span></a></code></pre></div>
<p>It says that the data set “Hansen99” is used, the dependent variable is “inva”, the variables in the data from column 4 to 20 are the explanatory variables in the linear part (though you can write down the names of them), the explanatory variables in the nonlinear part are the four ones in “indep_k”, and the potential transition variable is “vala” (Tobin’s Q).</p>
<p>Now you can see that the “NewPSTR” is basically defining the settings of the model.</p>
<p>Note that you can print the object of the class PSTR. By default, it gives you a summary of the PSTR model. They are mainly about which one is the dependent variable, which ones are explanatory variables and etc..</p>
</div>
<div id="specification" class="section level3">
<h3>Specification</h3>
<p>The following code does linearity tests</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1">pstr =<span class="st"> </span><span class="kw">LinTest</span>(<span class="dt">use=</span>pstr) </a>
<a class="sourceLine" id="cb8-2" title="2"><span class="kw">print</span>(pstr, <span class="st">&quot;tests&quot;</span>)</a>
<a class="sourceLine" id="cb8-3" title="3"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb8-4" title="4"><span class="co">#&gt; ## PSTR 1.2.4 (Orange Panel)</span></a>
<a class="sourceLine" id="cb8-5" title="5"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb8-6" title="6"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb8-7" title="7"><span class="co">#&gt; Results of the linearity (homogeneity) tests:</span></a>
<a class="sourceLine" id="cb8-8" title="8"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb8-9" title="9"><span class="co">#&gt; LM tests based on transition variable &#39;vala&#39;</span></a>
<a class="sourceLine" id="cb8-10" title="10"><span class="co">#&gt;   m  LM_X PV  LM_F PV HAC_X        PV HAC_F        PV</span></a>
<a class="sourceLine" id="cb8-11" title="11"><span class="co">#&gt;   1 125.3  0 28.99  0 30.03 4.819e-06 6.952 1.396e-05</span></a>
<a class="sourceLine" id="cb8-12" title="12"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb8-13" title="13"><span class="co">#&gt; Sequence of homogeneity tests for selecting number of switches &#39;m&#39;:</span></a>
<a class="sourceLine" id="cb8-14" title="14"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb8-15" title="15"><span class="co">#&gt; LM tests based on transition variable &#39;vala&#39;</span></a>
<a class="sourceLine" id="cb8-16" title="16"><span class="co">#&gt;   m  LM_X PV  LM_F PV HAC_X        PV HAC_F        PV</span></a>
<a class="sourceLine" id="cb8-17" title="17"><span class="co">#&gt;   1 125.3  0 28.99  0 30.03 4.819e-06 6.952 1.396e-05</span></a>
<a class="sourceLine" id="cb8-18" title="18"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb8-19" title="19"><span class="co">#&gt; ###########################################################################</span></a></code></pre></div>
<p>You can see that the function “LinTest” takes the PSTR object “pstr” and overwrites it when return. This is the way I recommend as the functions handling the PSTR object in the package update the object by adding new atrributes or members. However, the same function will change the values of the attributes it adds. You can of course create new PSTR objects to take the return values in order to save the results from different settings of the model.</p>
<p>You can do the wild bootstrap and wild cluster bootstrap by running the following code. (Warning! Don’t run it except that you have at least 50 cores!)</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" title="1">iB =<span class="st"> </span><span class="dv">5000</span> <span class="co"># the number of repetitions in the bootstrap</span></a>
<a class="sourceLine" id="cb9-2" title="2"><span class="kw">library</span>(snowfall)</a>
<a class="sourceLine" id="cb9-3" title="3">pstr =<span class="st"> </span><span class="kw">WCB_LinTest</span>(<span class="dt">use=</span>pstr,<span class="dt">iB=</span>iB,<span class="dt">parallel=</span>T,<span class="dt">cpus=</span><span class="dv">50</span>)</a></code></pre></div>
<p>It takes a long long time to run the bootstrap. This function is developed for those who work on some super-computation server with many cores and a large memory. Note that you will have to attach the “snowfall” package manually.</p>
<p>But of course, you can try the function on your personal computer by reducing the number of repetitions and the cores.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" title="1">pstr =<span class="st"> </span><span class="kw">WCB_LinTest</span>(<span class="dt">use=</span>pstr,<span class="dt">iB=</span><span class="dv">4</span>,<span class="dt">parallel=</span>T,<span class="dt">cpus=</span><span class="dv">2</span>)</a></code></pre></div>
</div>
<div id="estimation" class="section level3">
<h3>Estimation</h3>
<p>When you determine which transition variable to use for the estimation, in this case “inva”, you can estimate the PSTR model</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb11-1" title="1">pstr =<span class="st"> </span><span class="kw">EstPSTR</span>(<span class="dt">use=</span>pstr,<span class="dt">im=</span><span class="dv">1</span>,<span class="dt">iq=</span><span class="dv">1</span>,<span class="dt">useDelta=</span>T,<span class="dt">par=</span><span class="kw">c</span>(<span class="op">-</span><span class="fl">0.462</span>,<span class="dv">0</span>), <span class="dt">vLower=</span><span class="dv">4</span>, <span class="dt">vUpper=</span><span class="dv">4</span>)</a>
<a class="sourceLine" id="cb11-2" title="2"><span class="kw">print</span>(pstr,<span class="st">&quot;estimates&quot;</span>)</a></code></pre></div>
<p>By default, the “optim” method “L-BFGS-B” is used, but you can change the method for estimation by doing</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" title="1">pstr =<span class="st"> </span><span class="kw">EstPSTR</span>(<span class="dt">use=</span>pstr,<span class="dt">im=</span><span class="dv">1</span>,<span class="dt">iq=</span><span class="dv">1</span>,<span class="dt">useDelta=</span>T,<span class="dt">par=</span><span class="kw">c</span>(<span class="op">-</span><span class="fl">0.462</span>,<span class="dv">0</span>), <span class="dt">method=</span><span class="st">&quot;CG&quot;</span>)</a>
<a class="sourceLine" id="cb12-2" title="2"><span class="kw">print</span>(pstr,<span class="st">&quot;estimates&quot;</span>)</a>
<a class="sourceLine" id="cb12-3" title="3"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb12-4" title="4"><span class="co">#&gt; ## PSTR 1.2.4 (Orange Panel)</span></a>
<a class="sourceLine" id="cb12-5" title="5"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb12-6" title="6"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb12-7" title="7"><span class="co">#&gt; Results of the PSTR estimation:</span></a>
<a class="sourceLine" id="cb12-8" title="8"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb12-9" title="9"><span class="co">#&gt; Transition variable &#39;vala&#39; is used in the estimation.</span></a>
<a class="sourceLine" id="cb12-10" title="10"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb12-11" title="11"><span class="co">#&gt; Parameter estimates in the linear part (first extreme regime) are</span></a>
<a class="sourceLine" id="cb12-12" title="12"><span class="co">#&gt;        dt_75_0   dt_76_0   dt_77_0   dt_78_0  dt_79_0  dt_80_0   dt_81_0</span></a>
<a class="sourceLine" id="cb12-13" title="13"><span class="co">#&gt; Est  -0.002827 -0.007512 -0.005812 0.0003951 0.002464 0.006085 0.0004164</span></a>
<a class="sourceLine" id="cb12-14" title="14"><span class="co">#&gt; s.e.  0.002431  0.002577  0.002649 0.0027950 0.002708 0.002910 0.0029220</span></a>
<a class="sourceLine" id="cb12-15" title="15"><span class="co">#&gt;        dt_82_0   dt_83_0    dt_84_0  dt_85_0   dt_86_0   dt_87_0  vala_0</span></a>
<a class="sourceLine" id="cb12-16" title="16"><span class="co">#&gt; Est  -0.007802 -0.014410 -0.0009146 0.003467 -0.001591 -0.008606 0.11500</span></a>
<a class="sourceLine" id="cb12-17" title="17"><span class="co">#&gt; s.e.  0.002609  0.002701  0.0030910 0.003232  0.003202  0.003133 0.04073</span></a>
<a class="sourceLine" id="cb12-18" title="18"><span class="co">#&gt;       debta_0   cfa_0  sales_0</span></a>
<a class="sourceLine" id="cb12-19" title="19"><span class="co">#&gt; Est  -0.03392 0.10980 0.002978</span></a>
<a class="sourceLine" id="cb12-20" title="20"><span class="co">#&gt; s.e.  0.03319 0.04458 0.008221</span></a>
<a class="sourceLine" id="cb12-21" title="21"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb12-22" title="22"><span class="co">#&gt; Parameter estimates in the non-linear part are</span></a>
<a class="sourceLine" id="cb12-23" title="23"><span class="co">#&gt;        vala_1 debta_1    cfa_1  sales_1</span></a>
<a class="sourceLine" id="cb12-24" title="24"><span class="co">#&gt; Est  -0.10370 0.02892 -0.08801 0.005945</span></a>
<a class="sourceLine" id="cb12-25" title="25"><span class="co">#&gt; s.e.  0.03981 0.04891  0.05672 0.012140</span></a>
<a class="sourceLine" id="cb12-26" title="26"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb12-27" title="27"><span class="co">#&gt; Parameter estimates in the second extreme regime are</span></a>
<a class="sourceLine" id="cb12-28" title="28"><span class="co">#&gt;      vala_{0+1} debta_{0+1} cfa_{0+1} sales_{0+1}</span></a>
<a class="sourceLine" id="cb12-29" title="29"><span class="co">#&gt; Est    0.011300    -0.00500   0.02183    0.008923</span></a>
<a class="sourceLine" id="cb12-30" title="30"><span class="co">#&gt; s.e.   0.001976     0.01739   0.01885    0.004957</span></a>
<a class="sourceLine" id="cb12-31" title="31"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb12-32" title="32"><span class="co">#&gt; Non-linear parameter estimates are</span></a>
<a class="sourceLine" id="cb12-33" title="33"><span class="co">#&gt;       gamma        c_1</span></a>
<a class="sourceLine" id="cb12-34" title="34"><span class="co">#&gt; Est  0.6299 -0.0002008</span></a>
<a class="sourceLine" id="cb12-35" title="35"><span class="co">#&gt; s.e. 0.1032  0.7252000</span></a>
<a class="sourceLine" id="cb12-36" title="36"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb12-37" title="37"><span class="co">#&gt; Estimated standard deviation of the residuals is 0.04301</span></a>
<a class="sourceLine" id="cb12-38" title="38"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb12-39" title="39"><span class="co">#&gt; ###########################################################################</span></a></code></pre></div>
<p>The argument “useDelta” determines the type of the initial value for the smoothness parameter. By default “useDelta = F” means that the first initial value in “par” is the “gamma” instead of “delta”. Here we use the settings “useDelta = T” and “par = c(1.6, .5)” means that the first value of “par” is the “delta” and its value is 1.6. Note that “delta” and “gamma” has the relationship “gamma = exp(delta)”. Thus, the following two sentences are equivalent</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" title="1">pstr =<span class="st"> </span><span class="kw">EstPSTR</span>(<span class="dt">use=</span>pstr,<span class="dt">im=</span><span class="dv">1</span>,<span class="dt">iq=</span><span class="dv">1</span>,<span class="dt">useDelta=</span>T,<span class="dt">par=</span><span class="kw">c</span>(<span class="op">-</span><span class="fl">0.462</span>,<span class="dv">0</span>), <span class="dt">method=</span><span class="st">&quot;CG&quot;</span>)</a>
<a class="sourceLine" id="cb13-2" title="2">pstr =<span class="st"> </span><span class="kw">EstPSTR</span>(<span class="dt">use=</span>pstr,<span class="dt">im=</span><span class="dv">1</span>,<span class="dt">iq=</span><span class="dv">1</span>,<span class="dt">par=</span><span class="kw">c</span>(<span class="kw">exp</span>(<span class="op">-</span><span class="fl">0.462</span>),<span class="dv">0</span>), <span class="dt">method=</span><span class="st">&quot;CG&quot;</span>)</a></code></pre></div>
<p>Note that the estimation of a linear panel regression model is also implemented. The user can do it by simply running</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb14-1" title="1">pstr0 =<span class="st"> </span><span class="kw">EstPSTR</span>(<span class="dt">use=</span>pstr)</a>
<a class="sourceLine" id="cb14-2" title="2"><span class="kw">print</span>(pstr0,<span class="st">&quot;estimates&quot;</span>)</a>
<a class="sourceLine" id="cb14-3" title="3"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb14-4" title="4"><span class="co">#&gt; ## PSTR 1.2.4 (Orange Panel)</span></a>
<a class="sourceLine" id="cb14-5" title="5"><span class="co">#&gt; ###########################################################################</span></a>
<a class="sourceLine" id="cb14-6" title="6"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb14-7" title="7"><span class="co">#&gt; A linear panel regression with fixed effects is estimated.</span></a>
<a class="sourceLine" id="cb14-8" title="8"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb14-9" title="9"><span class="co">#&gt; Parameter estimates are</span></a>
<a class="sourceLine" id="cb14-10" title="10"><span class="co">#&gt;          dt_75     dt_76     dt_77    dt_78    dt_79    dt_80    dt_81</span></a>
<a class="sourceLine" id="cb14-11" title="11"><span class="co">#&gt; Est  -0.007759 -0.008248 -0.004296 0.002356 0.004370 0.008246 0.004164</span></a>
<a class="sourceLine" id="cb14-12" title="12"><span class="co">#&gt; s.e.  0.002306  0.002544  0.002718 0.002820 0.002753 0.002959 0.002992</span></a>
<a class="sourceLine" id="cb14-13" title="13"><span class="co">#&gt;          dt_82     dt_83    dt_84    dt_85    dt_86     dt_87     vala</span></a>
<a class="sourceLine" id="cb14-14" title="14"><span class="co">#&gt; Est  -0.005294 -0.010040 0.006864 0.009740 0.007027 0.0004091 0.008334</span></a>
<a class="sourceLine" id="cb14-15" title="15"><span class="co">#&gt; s.e.  0.002664  0.002678 0.003092 0.003207 0.003069 0.0030080 0.001259</span></a>
<a class="sourceLine" id="cb14-16" title="16"><span class="co">#&gt;          debta     cfa    sales</span></a>
<a class="sourceLine" id="cb14-17" title="17"><span class="co">#&gt; Est  -0.016380 0.06506 0.007957</span></a>
<a class="sourceLine" id="cb14-18" title="18"><span class="co">#&gt; s.e.  0.005725 0.01079 0.002412</span></a>
<a class="sourceLine" id="cb14-19" title="19"><span class="co">#&gt; ---------------------------------------------------------------------------</span></a>
<a class="sourceLine" id="cb14-20" title="20"><span class="co">#&gt; Estimated standard deviation of the residuals is 0.04375</span></a>
<a class="sourceLine" id="cb14-21" title="21"><span class="co">#&gt; ***************************************************************************</span></a>
<a class="sourceLine" id="cb14-22" title="22"><span class="co">#&gt; ###########################################################################</span></a></code></pre></div>
</div>
<div id="evaluation" class="section level3">
<h3>Evaluation</h3>
<p>The evaluation tests can be done based on the estimated model</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" title="1"><span class="co">## evaluatio tests</span></a>
<a class="sourceLine" id="cb15-2" title="2">pstr1 =<span class="st"> </span><span class="kw">EvalTest</span>(<span class="dt">use=</span>pstr,<span class="dt">vq=</span>pstr<span class="op">$</span>mQ[,<span class="dv">1</span>])</a></code></pre></div>
<p>Note that in the “EvalTest”, only one transition variable is taken each time for the no remaining nonlinearity test. This is different from the “LinTest” function which can take several transition variables. This is the reason why I save the results into new PSTR objects “pstr1” instead of overwriting. By doing so, I can save more test results from different transition variables in new objects.</p>
<p>The user can also do the wild bootstrap and wild cluster bootstrap in the following way, provided that he or she has the super-computation resources.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb16-1" title="1">iB =<span class="st"> </span><span class="dv">5000</span></a>
<a class="sourceLine" id="cb16-2" title="2">cpus =<span class="st"> </span><span class="dv">50</span></a>
<a class="sourceLine" id="cb16-3" title="3"></a>
<a class="sourceLine" id="cb16-4" title="4"><span class="co">## wild bootstrap time-varyint evaluation test </span></a>
<a class="sourceLine" id="cb16-5" title="5">pstr =<span class="st"> </span><span class="kw">WCB_TVTest</span>(<span class="dt">use=</span>pstr,<span class="dt">iB=</span>iB,<span class="dt">parallel=</span>T,<span class="dt">cpus=</span>cpus)</a>
<a class="sourceLine" id="cb16-6" title="6"></a>
<a class="sourceLine" id="cb16-7" title="7"><span class="co">## wild bootstrap heterogeneity evaluation test</span></a>
<a class="sourceLine" id="cb16-8" title="8">pstr1 =<span class="st"> </span><span class="kw">WCB_HETest</span>(<span class="dt">use=</span>pstr1,<span class="dt">vq=</span>pstr<span class="op">$</span>mQ[,<span class="dv">1</span>],<span class="dt">iB=</span>iB,<span class="dt">parallel=</span>T,<span class="dt">cpus=</span>cpus)</a></code></pre></div>
<p>Note that the evaluation functions do not accept the returned object “pstr0” from a linear panel regression model, as the evaluation tests are designed for the estimated PSTR model but not a linear one.</p>
</div>
<div id="plotting" class="section level3">
<h3>Plotting</h3>
<p>After estimating the PSTR model, you can plot the estimated transition function by running</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" title="1"><span class="kw">plot_transition</span>(pstr)</a></code></pre></div>
<p><img src="" /><!-- --></p>
<p>or a better plot with more arguments</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb18-1" title="1"><span class="kw">plot_transition</span>(pstr, <span class="dt">fill=</span><span class="st">&#39;blue&#39;</span>, <span class="dt">xlim=</span><span class="kw">c</span>(<span class="op">-</span><span class="dv">2</span>,<span class="dv">20</span>), <span class="dt">color =</span> <span class="st">&quot;dodgerblue4&quot;</span>, <span class="dt">size =</span> <span class="dv">2</span>, <span class="dt">alpha=</span>.<span class="dv">3</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb18-2" title="2"><span class="st">  </span>ggplot2<span class="op">::</span><span class="kw">geom_vline</span>(ggplot2<span class="op">::</span><span class="kw">aes</span>(<span class="dt">xintercept =</span> pstr<span class="op">$</span>c <span class="op">-</span><span class="st"> </span><span class="kw">log</span>(<span class="dv">1</span><span class="op">/</span><span class="fl">0.95</span> <span class="op">-</span><span class="st"> </span><span class="dv">1</span>)<span class="op">/</span>pstr<span class="op">$</span>gamma),<span class="dt">color=</span><span class="st">&#39;blue&#39;</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb18-3" title="3"><span class="st">  </span>ggplot2<span class="op">::</span><span class="kw">labs</span>(<span class="dt">x=</span><span class="st">&quot;customize the label for x axis&quot;</span>,<span class="dt">y=</span><span class="st">&quot;customize the label for y axis&quot;</span>,</a>
<a class="sourceLine" id="cb18-4" title="4">       <span class="dt">title=</span><span class="st">&quot;The Title&quot;</span>,<span class="dt">subtitle=</span><span class="st">&quot;The subtitle&quot;</span>,<span class="dt">caption=</span><span class="st">&quot;Make a caption here.&quot;</span>)</a></code></pre></div>
<p><img src="" /><!-- --></p>
<p>You can also plot the curves of the coefficients, the standard errors and the p-values against the transition variable.</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" title="1">ret =<span class="st"> </span><span class="kw">plot_coefficients</span>(pstr, <span class="dt">vars=</span><span class="dv">1</span><span class="op">:</span><span class="dv">4</span>, <span class="dt">length.out=</span><span class="dv">100</span>, <span class="dt">color=</span><span class="st">&quot;dodgerblue4&quot;</span>, <span class="dt">size=</span><span class="dv">2</span>)</a>
<a class="sourceLine" id="cb19-2" title="2">ret[[<span class="dv">1</span>]]</a></code></pre></div>
<p><img src="" /><!-- --></p>
<p>The plotting function <code>plot_response</code>, which depicts the relationship between <span class="math display">\[\begin{equation*}
[\phi_0 + \phi_1 g_{it}(q_{it} ; \gamma, c)] x_{it}
\end{equation*}\]</span> which I called response, some explanatory variable <span class="math inline">\(x_{it}\)</span> and the transition variable <span class="math inline">\(q_{it}\)</span> in the PSTR model.</p>
<p>The response <span class="math inline">\([\phi_0 + \phi_1 g_{it}(q_{it} ; \gamma, c)] x_{it}\)</span> is actually the contribution that the varabile <span class="math inline">\(x_{it}\)</span> makes to the conditional expectation of the dependent <span class="math inline">\(y_{it}\)</span> through the smooth transition mechanism.</p>
<p>We can see that the response against the variable is a straight line if there is no nonlinearity. We can plot a surface if the variable <span class="math inline">\(x_{it}\)</span> and the transition variable <span class="math inline">\(q_{it}\)</span> are distinct, with z-axis the response, x- and y- axises the two variables. And it becomes a curve if the variable <span class="math inline">\(x_{it}\)</span> and the transition variable <span class="math inline">\(q_{it}\)</span> are identical.</p>
<p>We make the graph by running</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb20-1" title="1">ret =<span class="st"> </span><span class="kw">plot_response</span>(<span class="dt">obj=</span>pstr, <span class="dt">vars=</span><span class="dv">1</span><span class="op">:</span><span class="dv">4</span>, <span class="dt">log_scale =</span> <span class="kw">c</span>(F,T), <span class="dt">length.out=</span><span class="dv">100</span>)</a></code></pre></div>
<p><code>ret</code> takes the return value of the function. We make the graphs for all the four variables in nonlinear part by using <code>vars=1:4</code> (variable names can also be used for specification). Note that we do not do it for the variables in the linear part, as they produce straight lines or planes. <code>log_scale</code> is a 2-vector of booleans specifying, for each graph, whether the first (some variable in the nonlinear part) or the second (the transition variable) should be log scaled. <code>length.out</code> gives the number of points in the grid for producing the surface or curve. A <code>length.out</code> of 100 points looks fine enough.</p>
<p>You may think of “what if I don’t wanna make all the variables log scaled?”. The solution is to make the graphs separately by running something like</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb21-1" title="1">ret1 =<span class="st"> </span><span class="kw">plot_response</span>(<span class="dt">obj=</span>pstr, <span class="dt">vars=</span><span class="dv">1</span>, <span class="dt">log_scale =</span> <span class="kw">c</span>(F,T), <span class="dt">length.out=</span><span class="dv">100</span>)</a>
<a class="sourceLine" id="cb21-2" title="2">ret2 =<span class="st"> </span><span class="kw">plot_response</span>(<span class="dt">obj=</span>pstr, <span class="dt">vars=</span><span class="dv">2</span>, <span class="dt">log_scale =</span> <span class="kw">c</span>(T,T), <span class="dt">length.out=</span><span class="dv">100</span>)</a></code></pre></div>
<p>Let us take a look the elements in <code>ret</code></p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb22-1" title="1"><span class="kw">attributes</span>(ret)</a>
<a class="sourceLine" id="cb22-2" title="2"><span class="co">#&gt; $names</span></a>
<a class="sourceLine" id="cb22-3" title="3"><span class="co">#&gt; [1] &quot;vala&quot;  &quot;debta&quot; &quot;cfa&quot;   &quot;sales&quot;</span></a></code></pre></div>
<p>We see that <code>ret</code> is a list containing elements whose names are the variables’ names that we specified when running <code>plot_response</code>.</p>
<p>Yes, but they are now plottable objects in the sense that you can simply plot them by running</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb23-1" title="1">ret<span class="op">$</span>vala</a></code></pre></div>
<p><img src="" /><!-- --></p>
<p>The numbers on the x-axis look not so good as it is difficult to find where the turning-point is.</p>
<p>The <code>ggplot2</code> package allows us to manually paint the numbers (the PSTR package collaborates very well with some prevailling packages), and even the label on x-axis (and many more).</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb24-1" title="1">ret<span class="op">$</span>vala <span class="op">+</span><span class="st"> </span>ggplot2<span class="op">::</span><span class="kw">scale_x_log10</span>(<span class="dt">breaks=</span><span class="kw">c</span>(.<span class="dv">02</span>,.<span class="dv">05</span>,.<span class="dv">1</span>,.<span class="dv">2</span>,.<span class="dv">5</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">5</span>,<span class="dv">10</span>,<span class="dv">20</span>)) <span class="op">+</span></a>
<a class="sourceLine" id="cb24-2" title="2"><span class="st">    </span>ggplot2<span class="op">::</span><span class="kw">labs</span>(<span class="dt">x=</span><span class="st">&quot;Tobin&#39;s Q&quot;</span>)</a></code></pre></div>
<p><img src="" /><!-- --></p>
<p>Now we see very clearly that the turning-point approximately 0.5 cut the curve into two regimes, and the two regimes behave so differently. This graph is about the lagged Tobin’s Q’s contribution to the expected investment. Low Q firms (whose potentials are evaluated to be low by the financial market) look rather reluctant to change their future investment plan, or maybe get changed.</p>
<p>Then let us proceed to the surfaces. Check the response from the debta by running</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb25-1" title="1">ret<span class="op">$</span>debta</a></code></pre></div>
<p>The graph is “living” and you can scracth on it by using your mouse. “vala_y” shows that the y-axis is the Q, and “debta_x” shows that the x-axis is the debt. The tool bar on up-right helps you to rotate, pan, zoom and save the graph.</p>
<p>Note that the transition variable Q is in log scale while debt is not.</p>
<p>It is very clear that low Q firms’ future investment will be affected by the current debt situation. The more debt there is, the less investment there will be. However, it is not the case for high Q firms who has good potential and is not sensitive to the debt.</p>
<p>The following two living graphs are for the cash flow and the sales.</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb26-1" title="1">ret<span class="op">$</span>cfa</a></code></pre></div>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb27-1" title="1">ret<span class="op">$</span>sales</a></code></pre></div>
</div>
</div>
</div>



<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
